<?php

//var_dump(file_get_contents("http://api.t.sina.com.cn/querymid.json?id=80516128&type=1"));
/*
CREATE TABLE `group`.`group_forum` (
`1` INT( 1 ) NOT NULL 

*/
		
		$handle = fopen("111.txt","r");
		
		
		$i =1;
		$sql ="";
		$sql_array = array();
		$primary_info = "";
		$comment="";
		echo "<pre>";
		while ($data = fgets($handle, 1000)) {
			//var_dump($data );
			$is_table_name =false;
			$data = substr($data ,0,strlen($data)-2);
			//var_dump($data );
			if(strlen($data) > 5 )
			{	
				$data1  = explode("\t",$data);
				//var_dump($data1);
				if(count($data1 ) < 3)
				{
					$data1  = explode(" ",$data);
					$is_table_name = true;
				}
				
				if($is_table_name)
				{
				
					$sql .=" CREATE TABLE `".$data1[0]."` ( <br>";

					$is_table_name =false;
				}
				else
				{
						if($i == 1 && stripos($data1[1],"int") !== false)
						{
							$sql_array[]= "`".trim($data1[0])."` ".$data1[1]." NOT NULL  COMMENT '".$data1[2]."' AUTO_INCREMENT ";
							$primary_info = "PRIMARY KEY (`".trim($data1[0])."`)";
						}
						else
						{
							$sql_array[]= "`".trim($data1[0])."` ".$data1[1]." NOT NULL  COMMENT '".$data1[2]."'";
						}
						$i++;
					
				}
			}
			else
			{
				//var_dump($sql_array);
				if($sql_array)
				{
					if($primary_info)
					{
						$sql_array[] = $primary_info ;
					}
					
					$sql .= join(",<br>",$sql_array) ;
					$sql .= "<br>) ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;<br><br>";
					echo $sql;
					unset($sql_array);
					unset($sql);
					unset($primary_info);
				}
			}

		}

		fclose($handle);
		
		
		
